use serde::{Serialize, Serializer};

/// 让迭代器可以序列化
///
/// 迭代器需要可复制，每次序列化都会复制迭代器。
pub struct IterSeq<I>(pub I);

impl<I, T> Serialize for IterSeq<I>
where
    I: Iterator<Item = T> + Clone,
    T: Serialize,
{
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        serializer.collect_seq(self.0.clone())
    }
}
